package com.key.win.business.chat.ctrl;

import com.key.win.base.auth.AuthenticationUtil;
import com.key.win.base.web.Result;
import com.key.win.business.chat.model.ImFriendGroup;
import com.key.win.business.chat.service.ImFriendGroupService;
import com.key.win.common.log.annotation.LogAnnotation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/friendGroup/*")
@Api("好友相关的api")
public class ImFriendGroupCtrl {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ImFriendGroupService imFriendGroupService;

    @GetMapping("/get/{id}")
    @ApiOperation(value = "获取Friend")
    @LogAnnotation(module = "im", recordRequestParam = false)
    public Result get(@PathVariable String id) {
        return Result.succeed(imFriendGroupService.getById(id));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除")
    @LogAnnotation(module = "im", recordRequestParam = true)
    public Result delete(@PathVariable String id) {
        boolean b = imFriendGroupService.removeById(id);
        return Result.result(b);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "添加/更新好友")
    @LogAnnotation(module = "im", recordRequestParam = true)
    public Result saveOrUpdate(@RequestBody ImFriendGroup imFriendGroup) {
        boolean b = imFriendGroupService.saveOrUpdate(imFriendGroup);
        return Result.result(b);
    }

    @GetMapping("/friend/{userId}")
    @ApiOperation(value = "根据用户获取FriendGroup")
    @LogAnnotation(module = "im", recordRequestParam = false)
    public Result getFriend(@PathVariable String userId) {
        return Result.succeed(imFriendGroupService.findFriendGroupByUserId(userId));
    }

    @GetMapping("/friend/cu")
    @ApiOperation(value = "获取当前用户的FriendGroup")
    @LogAnnotation(module = "im", recordRequestParam = false)
    public Result getFriendByCurrentUser() {
        return Result.succeed(imFriendGroupService.findFriendGroupByUserId(AuthenticationUtil.getUserId()));
    }
}
